import re
from typing import List, Tuple, Optional


PATTERN_1 = re.compile(
    r'''
    LBJTH\s*"([^"]+)"
    .*?
    RO\s*"([^"]+)"
    .*?
    DN\s*"([^"]+)"
    .*?
    LIST\s*
    ((?:[\d.]+|"[^"]*")(?:\s+(?:[\d.]+|"[^"]*"))*)
    ''',
    re.VERBOSE | re.DOTALL
)

PATTERN_2 = re.compile(
    r'''
    LBJTH\s*"([^"]+)"
    .*?
    DN\s*"([^"]+)"
    .*?
    LIST\s*
    ((?:[\d.]+|"[^"]*")(?:\s+(?:[\d.]+|"[^"]*"))*)
    ''',
    re.VERBOSE | re.DOTALL
)

PATTERN_3 = re.compile(
    r'''
    RO\s*"([^"]+)"
    .*?
    OD\s*([\d.]+)
    .*?
    LIST\s*
    ((?:[\d.]+|"[^"]*")(?:\s+(?:[\d.]+|"[^"]*"))*)
    ''',
    re.VERBOSE | re.DOTALL
)

PATTERN_4 = re.compile(
    r'''
    OI\s*([\d.]+)
    .*?
    CL\s*"([^"]+)"
    .*?
    YL\)\s*([\d.]+)
    .*?
    WD\)\s*([\d.]+)
    .*?
    WJ\s*"([^"]+)"
    .*?
    BH\s*"([^"]+)"
    .*?
    LIST\s*
    ((?:[\d.]+|"[^"]*")(?:\s+(?:[\d.]+|"[^"]*"))*)
    ''',
    re.VERBOSE | re.DOTALL
)

def extract_data(text: str) -> List[Tuple[str, str, Optional[str],  List[str]]]:
    results = []

    for match in PATTERN_4.finditer(text):
        try:
            field1 = match.group(1).strip()
            field2 = match.group(2).strip()
            field3 = match.group(3).strip()
            field4 = match.group(4).strip()
            field5 = match.group(5).strip()
            field6 = match.group(6).strip()
            list_str = match.group(7)
            list_values = re.findall(r'"([^"]*)"|(\S+)', list_str)
            list_values = [match[0] or match[1] for match in list_values]
            if field1 and field2 and field3 and list_values:
                results.append((field1, field2, field3, field4, field5, field6, list_values))
        except (AttributeError, IndexError):
            continue
    
    if not results:
        for match in PATTERN_1.finditer(text):
            try:
                field1 = match.group(1).strip()
                field2 = match.group(2).strip()
                field3 = match.group(3).strip()
                list_str = match.group(4)
                list_values = re.findall(r'"([^"]*)"|(\S+)', list_str)
                list_values = [match[0] or match[1] for match in list_values]
                if field1 and field2 and field3 and list_values:
                    results.append((field1, field2, field3, list_values))
            except (AttributeError, IndexError):
                continue

    if not results:
        for match in PATTERN_2.finditer(text):
            try:
                field1 = match.group(1).strip()
                field2 = match.group(2).strip()
                list_str = match.group(3)
                list_values = re.findall(r'"([^"]*)"|(\S+)', list_str)
                list_values = [match[0] or match[1] for match in list_values]
                if field1 and field2 and list_values:
                    results.append((field1, field2, list_values))
            except (AttributeError, IndexError):
                continue
            
    if not results:
        for match in PATTERN_3.finditer(text):
            try:
                field1 = match.group(1).strip()
                field2 = match.group(2).strip()
                list_str = match.group(3)
                list_values = re.findall(r'"([^"]*)"|(\S+)', list_str)
                list_values = [match[0] or match[1] for match in list_values]
                if field1 and field2 and list_values:
                    results.append((field1, field2, list_values))
            except (AttributeError, IndexError):
                continue
    
    return results